package entity.general;

public class Pair <S, T>
{
	public static void main (String [] args)
	{
		Pair <Integer, String> p1 = new Pair <>(1, "One");
		Pair <Integer, String> p2 = new Pair <>(1, "One");
		Pair <Integer, String> p3 = new Pair <>(1, "Two");
		Pair <Integer, String> p4 = new Pair <>(2, "Two");
		
		System.out.println(p1.equals(p2));
		System.out.println(p1.equals(p3));
		System.out.println(p1.equals(p4));		
	}
	
	S first;
	T second;
	int hc = 0;
	
	public Pair (S first, T second)
	{
		this.first = first;
		this.second = second;
	}
	
	public S getFirst()
	{
		return first;
	}
	
	public T getSecond()
	{
		return second;
	}
	
	public Pair <S, T> setFirst(S f)
	{
		return new Pair <S, T>(f, second);
	}

	public Pair <S, T> setSecond(T s)
	{
		return new Pair <S, T>(first, s);
	}

	public int hashCode()
	{
		if(hc == 0)
		{
			hc = first.hashCode() * second.hashCode();
		}
		return hc;
	}
	
	public boolean equals(Object other)
	{
		if(other instanceof Pair)
		{
			Pair otherP = (Pair)other;
			return first.equals(otherP.first) && second.equals(otherP.second);
		}
		return false;
	}
}
